﻿@{
    Layout = "~/Views/Shared/Create_Layout.cshtml";
}
<style>
    .layui-form { /*居中，文本框变短*/
        width: 38%;
        margin: 30px auto;
        text-align: center;
    }
</style>
<form class="layui-form" action="" lay-filter="layui">
    <div class="layui-form-item">
        <label class="layui-form-label required">旧的密码</label>
        <div class="layui-input-block">
            <input type="password" id="OldPassword" name="OldPassword" lay-verify="required" lay-reqtext="旧的密码不能为空" placeholder="请输入旧的密码" value="" class="layui-input">
            <tip>填写自己账号的旧的密码。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">新的密码</label>
        <div class="layui-input-block">
            <input type="password" id="NewPassword" name="NewPassword" lay-verify="required" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">再次输入新的密码</label>
        <div class="layui-input-block">
            <input type="password" id="ConfirmPassword" name="ConfirmPassword" lay-verify="required" lay-reqtext="新的密码不能为空" placeholder="请再次重复输入新的密码" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button lay-submit lay-filter="formsubmit" class="common_btn" id="submit">确认保存</button>



        </div>
    </div>

    <div class="rule">
        <p>1.密码长度为8-128位之间</p>
        <p>2.必须包含数字、大写字母、特殊符号</p>
        <p>3.键盘上连续字符不能超过3位</p>
        <p>4.连续或重复字母不能大于等于3位</p>
        <p>5.连续或重复数字不能大于等于3位</p>
    </div>
</form>
<script src="~/js/verifyRules.js" type="text/javascript"></script>
<script src="~/js/jsencrypt.min.js"></script>
<input id="pxkey" type="button" hidden="hidden" value="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCLqzqTeRC4uoRx2R61hda7Y82R
TKH2bWlgWigXaz3t337p3z47jJ4c/klQOIY5XTcxf1n+nzyd5QdJLy7KX76Izg0M
MRNg8TIzjFyQqbh6P2Hx6zqh0N9SSIF9HvUcJ7XuzMQc1E1te0d9gLOG7pO58l3a
r8UYG0t3uLnqlC64mwIDAQAB" />

<script>
    $(function() {

        layui.use(['jquery', 'layer', 'miniTab'], function() {
            var form = layui.form,
                miniTab = layui.miniTab;


            //监听提交
            form.on('submit(formsubmit)', function(data) {

                var entity = data.field;
                var url = '/SysPerson/ChangePassword'


                var password = $("#NewPassword").val();
                if (!password) {
                    alert("密码不能为空"); return;
                }

                var password_reg = /^(?=.*[0-9].*)(?=.*[A-Z].*)(?=.*[a-z].*)(?=.*[`~!@Html.Raw("@")#$%^&*()_\-+=<>.?:"{}].*).{8,64}$/;
                // 正则验证密码  包含大小写字母和数字 并且      长度8-128
                if (!password_reg.test(password)) {
                    alert("密码格式错误");
                    return;
                }

                if (_isKeyBoardContinuousChar(password)) {
                    alert("键盘上连续字符不能超过3位");
                    return;
                }
                if (_isContinuousChar(password)) {
                    alert("输入连续字母不能有3位");
                    return;
                }
                if (_isContinuousOrRepeatNum(password)) {
                    alert("连续或重复数字不能有3位");
                    return;
                }

                var oldPassword = $("#OldPassword").val();
                if (oldPassword == password) {
                    alert("新密码和旧密码不能一样"); return;
                } 

                var confirmPassword = $("#ConfirmPassword").val();
                if (confirmPassword != password) {
                    alert("两次输入的新密码要一致"); return;
                }

                var encrypt = new JSEncrypt();
                encrypt.setPublicKey($("#pxkey").val());
                entity.OldPassword = encrypt.encrypt(oldPassword);
                entity.NewPassword = encrypt.encrypt(password);
                entity.ConfirmPassword = encrypt.encrypt(confirmPassword);



                var data = ajaxPost(url, entity);

                if (data.code == 200) {
                    layer.alert(data.msg, {
                        title: "成功"
                    });
                    //关闭当前tab页面
                    miniTab.delete(url, true);
                } else {
                    layer.alert(data.msg, {
                        title: "失败"
                    });
                }

                return false;
            });
        });

    })




</script> 